﻿using MasterMasterMode.Common.Systems;
using MasterMasterMode.Content.Biomes;
using Terraria;
using Terraria.GameContent.Bestiary;
using Terraria.ID;
using Terraria.ModLoader;

namespace MasterMasterMode.Content.NPCs
{
    public class EnlargedGoldfishWarrior : ModNPC
    {
        public override void SetStaticDefaults()
        {
            Main.npcFrameCount[Type] = Main.npcFrameCount[NPCID.GoldfishWalker];
        }
     

        public override void SetDefaults()
        {
            NPC.width = 24;
            NPC.height = 44;
            NPC.damage = 40;
            NPC.defense = 12;
            NPC.lifeMax = 300;
            NPC.HitSound = SoundID.NPCHit1;
            NPC.DeathSound = SoundID.NPCDeath1;
            NPC.value = 50f;
            NPC.aiStyle = 3;
            AIType = 524;
            AnimationType = NPCID.GoldfishWalker;
            NPC.knockBackResist = 0.5f;
            NPC.noTileCollide = false;
            NPC.noGravity = false;
            SpawnModBiomes = [ModContent.GetInstance<Armyofwarriorgoldfishes>().Type];
            Music = MusicID.OldOnesArmy;
        }
        public override bool CheckDead()
        {
            if (InvasionSystem.ArmyofwarriorgoldfishesUp)
            {
                Main.invasionSize--;
            }
            return true;
        }
        public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry)
        {
            bestiaryEntry.Info.AddRange([
                BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Times.DayTime,
                BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Biomes.Surface,
                new FlavorTextBestiaryInfoElement("Mods.MasterMasterMode.Bestiary.EnlargedGoldfishWarrior"),
            ]);
        }
        public override void HitEffect(NPC.HitInfo hit)
        {
            if (NPC.life <= 0)
            {
                for (int i = 0; i < 10; i++)
                {
                    Dust.NewDust(NPC.position, NPC.width, NPC.height, DustID.Water, 2.5f * hit.HitDirection, -2.5f, 0, default, 1.2f);
                }
                Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, 553, 3f);
                Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, 554, 3f);
            }
            else
            {
                for (int i = 0; i < 3; i++)
                {
                    Dust.NewDust(NPC.position, NPC.width, NPC.height, DustID.Water, hit.HitDirection, -1f, 0, default, 0.8f);
                }
            }
        }
    }
}

